/**
 * 该js文件里面存放整个系统公用的小js方法（不能按照功能划分）
 */
$(function(){
	$(".bookdao-combobox","form").each(
			function(){
				$(this).addClass('easyui-combobox');
			}
		);
	$(".bookdao-datebox","form").each(
			function(){
				$(this).addClass('easyui-datebox');
				$(this).datebox();
			}
	);
	$(".easyui-combobox").combobox();
	//添加背景色
	$(".easyui-combobox","form").each(
			function(){
				var options=$(this).combobox('options');
				if(options.multiple){
					var inputText =$(this).next().find('input')[0];
					$(inputText).css({'background-color': '#F0F8FF'});
				}
				if(options.panelHeight==200){
					$(this).combobox({'panelHeight':'auto'});
				}else{
					$(this).combobox({'panelHeight':options.panelHeight});
				}
			}
		);
	$(".bookdao-tooltip").each(function(){
		$(this).addClass("fa").addClass("fa-question-circle");
		$(this).tooltip({
			onShow:function(){
				$(this).tooltip('tip').css({backgroundColor: '#F7F709',borderColor: '#F7F709'});
			}
		});
	});
	initDoubleUpDown();
	moreWords('more-words',12);
	htmlValue();
	
	//注册选择框
	var oasisSelectorRegister = function(type,xml,propertyId,propertyName){
		var oasisInput = $("input[type='"+type+"']");
		var len = oasisInput.length;
		for(var i = 0; i < len; i++){
			var dataOptions = $(oasisInput[i]).attr("data-options");
			if(!isNull(dataOptions)){
				dataOptions = eval("({"+dataOptions+"})");
			}else{
				dataOptions = {};
			}
			if(type == 'oasis_product'){
				dataOptions.height = 550;
			}
			$(oasisInput[i]).oasis_selector(dataOptions,xml,propertyId,propertyName);
		}
	}
	//版权合同 
	oasisSelectorRegister('oasis_ep_contract','common/all_ep_contract_selector.xml','copyrightContractId','code');
	//权限组
	oasisSelectorRegister('oasis_privilege_group','common/all_ad_privilege_group_selector.xml','PRIVILEGE_GROUP_ID','NAME');
	//物流公司
	oasisSelectorRegister('oasis_logistics','common/all_logistics_selector.xml','LOGISTICS_ID','NAME');
	//权利人
	oasisSelectorRegister('oasis_rightHolderId','ep/ep_cooperate_company_author.xml','rightHolderId','name');
	//作者
	oasisSelectorRegister('oasis_author','ep/ep_author.xml','author','name');
	//原出版社Id
	oasisSelectorRegister('oasis_originalPublishHouseId','ep/ep_cooperate_company_houseId.xml','originalPublishHouseId','name');
	//代理 
	oasisSelectorRegister('oasis_cooperateCompanyId','ep/ep_cooperate_company_agent.xml','agent','name');
	//人员选择框
	oasisSelectorRegister('oasis_staff','common/all_staff_selector.xml','staffId','pname');
	//客户选择框
	oasisSelectorRegister('oasis_customer','common/all_customer_selector.xml','customerId','name');
	//供应商选择框
	oasisSelectorRegister('oasis_supplier','common/all_supplier_selector.xml','supplierId','name');
	//商品选择框
	oasisSelectorRegister('oasis_product','common/all_product_selector.xml','PRODUCT_ID','NAME');
	
	//征订统计商品选择框
	oasisSelectorRegister('oasis_productss','common/all_product_subscriptionOrder.xml','PRODUCT_ID','NAME');
	
	//省选择框
	oasisSelectorRegister('oasis_province','common/all_cu_province_selector.xml','provinceId','provinceName');
	//市选择框
	oasisSelectorRegister('oasis_city','common/all_cu_city_selector.xml','cityId','cityName');
	//出版社
	oasisSelectorRegister('oasis_publish','common/all_publish_house_selector.xml','publishHouseId','name');
	//码表
	oasisSelectorRegister('oasis_lookup','sys/cu_lookupcode_selector.xml','lookupCode','codeName');
	//合同
	oasisSelectorRegister('oasis_copyright','ep/ep_copyright_contract_code.xml','copyrightContractId','code');
	//财务供应商
	oasisSelectorRegister('oasis_financialSupplier','ep/ep_copyright_contract_selector.xml','financialSupplier','name');
	//征订目录
	oasisSelectorRegister('oasis_subscriptionContent','sd/sd_subscription_content_selector.xml','subscriptionContentId','CODE');
	//商品编码
	oasisSelectorRegister('oasis_productCode','ep/ep_copyright_contract_product.xml','productId','productCode');
	//返点合同
	oasisSelectorRegister('oasis_contractCode','sd/sd_sale_contract_name.xml','saleContractId','name');
	
	//选择版权合同弹出框                                                             
	oasisSelectorRegister('oasis_prepaymentHistory','ep/ep_prepayment_history.xml','copyrightContractId','code');
	
	//修改商品定价选择商品弹框 
	oasisSelectorRegister('oasis_prodcutPriceAlter','mm/mm_prodcut_price_alter.xml','productId','productName');
	//新书报订单商品选择框
	oasisSelectorRegister('oasis_productOfNew','common/all_product_selector_new.xml','PRODUCT_ID','STANDARD_NAME');
    //选题单选择框
	oasisSelectorRegister('oasis_topic','common/all_topic_selector.xml','topicId','topicName');
	//选题单初始化选择全部
	oasisSelectorRegister('oasis_topic_all','common/all_all_topic_selector.xml','topicId','topicName');
	//印制--供应商选择框
	oasisSelectorRegister('oasis_pi_supplier','common/all_pi_supplier_selector.xml','id','name');
	//货主选择全部
	oasisSelectorRegister('oasis_pi_owner','common/all_pi_owner_selector.xml','id','name');
	//材料选择全部
	oasisSelectorRegister('oasis_pi_metarials','common/all_pi_metarials_selector.xml','id','metaName');
	//Easyui-datebox组件扩展，只显示年-月
	$(".month-box").datebox({
        onShowPanel: function () {//显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
        	var box = this;
        	var p = $(box).datebox('panel'), //日期选择对象
            tds = false, //日期选择对象中月份
            span = p.find('span.calendar-text'); //显示月份层的触发控件
            span.trigger('click'); //触发click事件弹出月份层
            if (!tds) setTimeout(function () {//延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
                tds = p.find('div.calendar-menu-month-inner td');
                tds.unbind("click")
                tds.bind("click",function (e) {
                    e.stopPropagation(); //禁止冒泡执行easyui给月份绑定的事件
                    var year = /\d{4}/.exec(span.html())[0]//得到年份
                    , month = parseInt($(this).attr('abbr'), 10); //月份，这里不需要+1
                    $(box).datebox('hidePanel')//隐藏日期对象
                    .datebox('setValue', year + '-' + month); //设置日期的值
                    //支持easyui_datebox的onSelect事件，xuzhen 20160923
                    var options = $(box).datebox("options");
                    if(typeof options.onSelect == "function"){
                    	options.onSelect.call(box,new Date(parseInt(year, 10), parseInt(month, 10) - 1, 1));
                    }
                });
            }, 0)
        },
        parser: function (s) {
            if (!s) return new Date();
        	var min = $(this).datebox("options").min;
        	var arr = s.split('-');
        	var selectDate = new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
        	if(!isNull(min)){
        		var minArray = min.split('-');
        		var minDate = new Date(parseInt(minArray[0], 10), parseInt(minArray[1], 10) - 1, 1);
        		if(minDate.getTime()>selectDate.getTime()){
        			return minDate;
        		}
        	}
            return selectDate;
        },
        formatter: function (d) { 
        		return d.getFullYear() + '-' + (d.getMonth()+1);
        }
    });
	
	//处理下拉框多选逻辑（选[全部]的时候自动清除已选项；一个没选中时自动选中[全部]）
	$(".easyui-combobox").each(
		function(){
			var options = $(this).combobox("options");
			var defaultOptions = {
					multiple:false,
					onSelect:null,
					onUnselect:null
			};
			var setting=$.extend({},defaultOptions,options);
			if(setting["multiple"]){
				if(options["onUnselect"]!=onUnSelectMultiCombobox){
					var oldOnUnselectFunction = options["onUnselect"];
					options["onUnselect"]=function(n){
						onUnSelectMultiCombobox.call(this,n);
						oldOnUnselectFunction.call(this,n)
					};
				}
				if(options["onSelect"]!=onSelectMultiCombobox){
					var oldOnSelectFunction = options["onSelect"];
					options["onSelect"]=function(n){
						onSelectMultiCombobox.call(this,n);
						oldOnSelectFunction.call(this,n)
					};
				}
			}
		}
	);
	
	var oasisCombotreeRegister = function(type,combotreeId){
		var oasisInput = $("input[type='"+type+"']");
		var len = oasisInput.length;
		for(var i = 0; i < len; i++){
			var dataOptions = $(oasisInput[i]).attr("data-options");
			if(!isNull(dataOptions)){
				dataOptions = eval("({"+dataOptions+"})");
			}else{
				dataOptions = {};
			}
			dataOptions["url"] = BASE_PATH + "/commonController/treeData/"+combotreeId;
			$(oasisInput[i]).combotree(dataOptions);
		}
	}
	oasisCombotreeRegister("oasis_combotree_department","departmendCombotree");
	oasisCombotreeRegister("oasis_combotree_code","codeCombotree");
});

/**
 * 重新Number对象的toFixed方法，修复小数位保留错误
 */
Number.prototype.toFixed = function(d){
	  var s=this+""; 
	    if(!d)d=0; 
	    if(s.indexOf(".")==-1)s+="."; 
	    s+=new Array(d+1).join("0"); 
	    if(new RegExp("^(-|\\+)?(\\d+(\\.\\d{0,"+(d+1)+"})?)\\d*$").test(s)){
	        var s="0"+RegExp.$2,pm=RegExp.$1,a=RegExp.$3.length,b=true;
	        if(a==d+2){
	            a=s.match(/\d/g); 
	            if(parseInt(a[a.length-1])>4){
	                for(var i=a.length-2;i>=0;i--){
	                    a[i]=parseInt(a[i])+1;
	                    if(a[i]==10){
	                        a[i]=0;
	                        b=i!=1;
	                    }else break;
	                }
	            }
	            s=a.join("").replace(new RegExp("(\\d+)(\\d{"+d+"})\\d$"),"$1.$2");

	        }if(b)s=s.substr(1); 
	        return (pm+s).replace(/\.$/,"");
	    }return this+"";
}

/**
 * 解决easyui-rownum宽度过窄，长数字显示不全问题 
 */
$.extend($.fn.datagrid.methods, {
    fixRownumber : function (jq) {
        return jq.each(function () {
            var panel = $(this).datagrid("getPanel");
            //获取最后一行的number容器,并拷贝一份
            var clone = $(".datagrid-cell-rownumber", panel).last().clone();
            //由于在某些浏览器里面,是不支持获取隐藏元素的宽度,所以取巧一下
            clone.css({
                "position" : "absolute",
                left : -1000
            }).appendTo("body");
            var width = clone.width("auto").width();
            //默认宽度是25,所以只有大于25的时候才进行fix
            if (width > 25) {
                //多加5个像素,保持一点边距
                $(".datagrid-header-rownumber,.datagrid-cell-rownumber", panel).width(width + 10);
                //修改了宽度之后,需要对容器进行重新计算,所以调用resize
                $(this).datagrid("resize");
                //一些清理工作
                clone.remove();
                clone = null;
            } else {
                //还原成默认状态
                $(".datagrid-header-rownumber,.datagrid-cell-rownumber", panel).removeAttr("style");
            }
        });
    }
});
//下拉框js，全部选择的逻辑
function onSelectMultiCombobox(sel){
	var allval = $(this).combobox("getData");
	var options = $(this).combobox("options");
	var valueField = options.valueField;
    var allth = allval.length;
    if (sel[valueField] != 'cbb_all'){
        $(this).combobox("unselect", 'cbb_all');
    }else{
        for (var i=0;i<allth;i++) {
            if (allval[i][valueField] != 'cbb_all') {
                $(this).combobox("unselect", allval[i][valueField]);
            }
        }
    }
}
//下拉框js，全部选择的逻辑
function onUnSelectMultiCombobox(sel){
	var values = $(this).combobox("getValues");
	if(values.length == 0){
		var allval = $(this).combobox("getData");
		var options = $(this).combobox("options");
		var valueField = options.valueField;
	    var allth = allval.length;
        for (var i=0;i<allth;i++) {
            if (allval[i][valueField] == 'cbb_all') {
                $(this).combobox("select", "cbb_all");
                break;
            }
        }
	}
	
}
/**
 * 替换HTML标签（换成真正的值）
 * @param val
 * @returns
 */
function replaceHtmlToTag(val){
	val = val.replace(new RegExp(/&gt;/g), ">");  
	val = val.replace(new RegExp(/&lt;/g), "<");  
	val = val.replace(new RegExp(/&nbsp;/g), " ");  
	val = val.replace(new RegExp(/&quot;/g), "\"");  
	val = val.replace(new RegExp(/&#39;/g), "\'");  
//	val = val.replace(new RegExp(/\\\\/g), "\\\\");
	val = val.replace(new RegExp(/\<br\/\>/g), "\n");  
	val = val.replace(new RegExp(/\\r/g), "\r");
	return val;
}
//换种取值方式兼容datagrid懒加载数据
function getRows(datagridObject){
    var opts=$(datagridObject).datagrid('options');
    var data=$(datagridObject).datagrid('getData');
    var rows=data.rows;
    if(opts.view.type == 'scrollview'){
        var firstRow=data.firstRows;
        if(firstRow && firstRow.length>0){
        	rows=firstRow;
        }
    }
    return rows;
}
/**
 * 还原内容为HTML标签
 * @param val
 * @returns
 */
function restoreHtml(val){
	val = val.replace(new RegExp(/\>/g), "&gt;");  
	val = val.replace(new RegExp(/\</g), "&lt;");
	val = val.replace(new RegExp(/\n/g), "<br/>");
	val = val.replace(new RegExp(/\s/g), "&nbsp;");  
	val = val.replace(new RegExp(/\"/g), "&quot;");  
	val = val.replace(new RegExp(/\'/g), "&#39;");  
//	val = val.replace(new RegExp(/\\/g), "\\\\");  
	val = val.replace(new RegExp(/\r/g), "\\r"); 
	return val;
}
//对input或者textarea中的特殊字符进行还原
function htmlValue(){
	var htmlValue = $(".html-value");
	for(var i = 0; i < htmlValue.length; i++){
		var val = $(htmlValue[i]).val();
		if(isNull(val)){
			val = "";
		}
		val = replaceHtmlToTag(val);
		$(htmlValue[i]).val(val)
	}
}

/**
 * 详情页信息截取
 * 解决问题1：可以支持添加超链接
 * 2.对文本值的第一行进行字符判断
 */
function moreWords(cls,length){
	var moreWords = $("."+cls);
	for(var i = 0; i < moreWords.length; i++){
		var val = $(moreWords[i]).html();
		val = $.trim(val);
		if(!isNull($(moreWords[i]).attr("tag")) && $(moreWords[i]).attr("tag")=="true"){
			var tempLen = 0;
			var finalTempStr = "";
			var tempVal = val.replace(/<.*?>(.*?)<\/.*?>/g,function(s,front, tag){
				if(tempLen >= length){
					return "";
				}
				var tempStr = "";
				if(tag > 0){
					for(var i = tag-1; i < val.length; i++){
						if(val.charAt(i) == "<"){
							break;
						}
						tempStr+=val.charAt(i)
					}
				}
				
				
				var tl = tempLen;
				var newResult = "";
				var tlt = tempLen;
				tempLen = tempLen+tempStr.length;
				if(tempLen > length){
					newResult += tempStr.substring(0,length-tlt);
				}else{
					newResult += tempStr;
				}
				tempLen = tempLen + front.length;
				if(tempLen > length){
					newResult += s.replace(front+"</",front.substring(0,length-tl)+"</");
				}
				
				if(newResult.length == 0){
					newResult = s;
				}
				finalTempStr+=newResult;
			})
			val = finalTempStr;
			var moreBtnAndOriginal = "<a href='javascript:void(0);' class='more-words-more'>更多...</a>" +
					"<div class='more-words-original'>"
					+$.trim($(moreWords[i]).html())+"</div>";
			$(moreWords[i]).html(val+moreBtnAndOriginal);
		}else{
			var brIndex = val.indexOf("<br/>");
			if(brIndex == -1){
				brIndex = val.indexOf("<br>");
			}
			if(brIndex == -1){
				brIndex = val.indexOf("<BR>");
			}
			if(brIndex == -1){
				brIndex = val.indexOf("<BR/>");
			}
			var isBr = false;
			if(brIndex != -1){
				val = val.substring(0,brIndex);
				isBr = true;
			}
			var moreBtnAndOriginal = "<a href='javascript:void(0);' class='more-words-more'>更多...</a>" +
					"<div class='more-words-original'>"
					+$.trim($(moreWords[i]).html())+"</div>";
			val = replaceHtmlToTag(val);
			var valLen = val.length;
			if(valLen > length){
				val = restoreHtml(val.substring(0,length))+moreBtnAndOriginal;
			}else if(isBr){
				val += moreBtnAndOriginal;
			}
			$(moreWords[i]).html(val);
		} 
		
	}
	if($("div.more-words-dialog").length==0){
		$("body").append("<div class='more-words-dialog' style='overflow-y: auto;'></div>");
	}
	$('.more-words-dialog').dialog({
 		collapsible:false,
 		minimizable:false,
 		maximizable:false,
 		resizable:false,
 		draggable:true,
 		inline:true,
 		shadow:false,
 		closed:true,
 		top:120,
 		title:"详情",
	    width:500,
	    height:300,
	    modal:true,
	    onClose:function(){
	    	$("#more-words-dialog").html("");
	    },
	    buttons:[{
			text:'关闭',
			handler:function(){
				$(".more-words-dialog").dialog("close");
			}
		}]
	});
	$(".more-words-more").click(function(){
		$(".more-words-dialog").html($(this).next("div[class='more-words-original']").html());
		$('.more-words-dialog').dialog("open");
	});
}

/**
 * 金额转换成大写
 * @returns {String}
 */
String.prototype.cnCurrency = function(){
	var cnDecimals = new Array("角", "分");
	var cnDigit = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖");
	var cnUnit = new Array( [ "元", "万", "亿" ], [ "", "拾", "佰", "仟" ] );
	var numberString = this;
	var result = "";
	var splitNumber = numberString.split('\.');
	var integer = splitNumber[0];
	var decimal = splitNumber[1];
	var decimalLength = decimal.length;
	if(decimalLength > 2){
		decimal = decimal.substring(0,2);
		decimalLength = 2;
	}
	for(var i = 0; i < decimalLength; i++){
		result += cnDigit[Number(decimal.charAt(i))];
		result += cnDecimals[i];
	}
	var integerCn = "";
	for(var i = 0; i < integer.length; i++){
		integerCn += cnDigit[Number(integer.charAt(i))];
	}
	var integerParts = integerCn.length % 4 > 0 ? integerCn.length / 4 +1 : integerCn.length / 4;
	var unitIndex = 0;
	for(var i = 0; i < integerParts; i++){
		var end = integerCn.length - i * 4;
		var start = end - 4;
		if(start < 0){
			start = 0;
		}
		var part = integerCn.substring(start,end);
		var tempStr = "";
		for(var j = 0; j < part.length; j++){
			var partChar = part.charAt( j );
			tempStr += partChar;
			if(partChar != cnDigit[0]){
				tempStr += cnUnit[1][part.length - j -1];
			}
		}
		if(tempStr.length > 0){
			tempStr += cnUnit[0][unitIndex++];
			if(unitIndex > 2){
				unitIndex = 1;
			}
		}
		result = tempStr + result ;
	}
	return result;
	
}

/** 扩展数组属性----START*/

/**
 * 数组中指定元素得位置
 */
Array.prototype.indexOf = function(val) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == val){
			return i;
		}
	}
	return -1;
};
/**
 * 删除数组指定元素
 */
Array.prototype.remove = function(val) {
	var index = this.indexOf(val);
	if (index > -1) {
		this.splice(index, 1);
	}
};
/** 扩展数组属性----END*/
/**
 * 隐藏
 */
function doubleUpAction(event){
	var parent = null;
	if(event.target.nodeName=="LI"){
		parent = $(this).parent(".widget-header");
		
	}else if(event.target.nodeName=="DIV"){
		parent = $(this);
	}
	$(parent.next(".widget-body")).slideUp(200,function(){
		$(window).resize();
	});

	var doubleUp = parent.find("li[class='double-up-down-common double-up']");
	$(doubleUp[0]).remove();
	var allChindTag = $(parent).children();
	var isAppend = false;
	for(var i = 0; i < allChindTag.length; i++){
		if($(allChindTag[i]).css("float")=="right"){
			$(allChindTag[i]).before("<li class='double-up-down-common double-down'></li>");
			isAppend = true;
			break;
		}
	}
	if(!isAppend){
		parent.append("<li class='double-up-down-common double-down'></li>");
	}
	$(".double-down").bind("click",doubleDownAction);
	$(parent).unbind("click");
	$(parent).bind("click",doubleDownAction);
}
/**
 * 显示
 */
function doubleDownAction(event){
	var parent = null;
	if(event.target.nodeName=="LI"){
		parent = $(this).parent(".widget-header");
		
	}else if(event.target.nodeName=="DIV"){
		parent = $(this);
	}
	$(parent.next(".widget-body")).slideDown(200,function(){
		$(window).resize();
	});
	var doubleDown = parent.find("li[class='double-up-down-common double-down']");
	$(doubleDown[0]).remove();
	var allChindTag = $(parent).children();
	var isAppend = false;
	for(var i = 0; i < allChindTag.length; i++){
		if($(allChindTag[i]).css("float")=="right"){
			$(allChindTag[i]).before("<li class='double-up-down-common double-up'></li>");
			isAppend = true;
			break;
		}
	}
	if(!isAppend){
		parent.append("<li class='double-up-down-common double-up'></li>");
	}
	$(".double-up").bind("click",doubleUpAction);
	$(parent).unbind("click");
	$(parent).bind("click",doubleUpAction);
}
/**
 * 初始化开启、关闭按钮
 */
function initDoubleUpDown(){
	var $doubleUpDown = $(".double-up-down");
	if($doubleUpDown.length>0){
		var doubleUp = $doubleUpDown.find("li[class='double-up']");
		var doubleDown = $doubleUpDown.find("li[class='double-down']");
		if(doubleUp.length>0){
			$(doubleUp).remove();
		}
		if(doubleDown.length>0){
			$(doubleDown).remove();
		}
		for(var j = 0; j < $doubleUpDown.length; j++){
			var allChindTag = $($doubleUpDown[j]).children();
			var isAppend = false;
			for(var i = 0; i < allChindTag.length; i++){
				if($(allChindTag[i]).css("float")=="right"){
					$(allChindTag[i]).before("<li class='double-up-down-common double-up'></li>");
					isAppend = true;
					break;
				}
			}
			if(!isAppend){
				$($doubleUpDown[j]).append("<li class='double-up-down-common double-up'></li>");
			}
		}
		$(".double-up").bind("click",doubleUpAction);
		$doubleUpDown.bind("click",doubleUpAction);
	}
	
}
/**
 * 值是否为空
 * @param value
 * @returns {Boolean}
 */
function isNull(value){
	if(!(typeof value == 'undefined' || value == null)){
		value = value+"";
	}else{
		return true;
	}
	return value.length == 0;
}
/**
 * 格式化码值
 * @param value
 * @returns
 */
function formatterLookupCode(value){
	if(isNull(value)){
		return "";
	}
	return CODE_MAP[value];
}

/**
 * 切换库,级联查询商品对应的库存initProductStockByStorage
 * @param datagridId
 * @param typeId
 */
function initProductStockByStorage(options){
	var defaults={
			datagridId:'sales_order_list_table',//明细datagridId
			storageTypeId:'storageTypeId',//库 input的id
			productId:'productId',//明细中商品id
			stock:'stock'//明细中库存的字段名
	};
	var setting=$.extend({},defaults,options);
	$("#"+ setting.storageTypeId).combobox("options").onChange = function(newValue, oldValue){
		if(oldValue.length>0){
			var rows = $("#"+setting.datagridId).datagrid("getRows");
			if(rows.length>0){
				var productIds="";
				for(var i=0;i<rows.length;i++){
					var row = rows[i];
					productIds += row.productId;
					if(i < (rows.length-1)){
						productIds += ",";
					}
				}
				$.ajax({
			        type: "POST",
			        url: BASE_PATH+"/commonController/initStockByProductId",
			        data:{
			        	productIds:productIds,
			        	storageTypeId:newValue
			        	},
			        dataType:'json',
			        success: function (data) {
			        	//alert('参数值:'+JSON.stringify(data));
			        	if(!data.error){
			        		var newRows=[];
			        		for(var i = 0; i < rows.length; i++){
			        			rows[i][setting.stock] = data[rows[i][setting.productId]];
			        		}
			        		$("#" + setting.datagridId).datagrid("loadData",rows);
			        	}else{
			        		$.messager.alert("提示：", data.msg, "info");
			        	}
			        	
			        }
				});
			}
		}
	}
}

/**
 * 公共弹出框
 * 使用方法：
 * 注：被加载页面提供一个getDictionarySelections()方法，返回一个值，这个值会在确定按钮按下去之后返回给回调函数
 * PageDialog.openSelector({
 * 		'url':'', //需要加载的页面地址
		'width': 800, //对话框宽度
		'height':500, //对话框高度
		'callBack': $.noop(),//回调函数
		'onLoadCallBack':$.noop(),//页面加载完执行的函数，会传递过来一个参数 frameId 可以使用 frameId.function()直接调用被加载页面中的JS方法
		'urlparams' : '',//请求参数，使用JSON的方式传递过来
		'okClose':false//确定后是否关闭，默认不关闭
 * });
 */
var PageDialog = {
	openSelector : function (options){
		var defaults = {
			'url':'',
			'width': 800, 
			'height':500, 
			'callBack': $.noop(),
			'onLoadCallBack':$.noop(),
			'onOpen':$.noop(),
			'onClose':$.noop(),
			'urlparams' : {},
			'okClose':false,
			'confirmId':'confirm', //弹出框页面 确定 按钮的ID值
			'hasConfirm':true,
			'enter':false,
			'newButtons':[]
		};
		var dialogSize = $(".page-dialog").length;
		var dialogId = "#PageDialog"+(dialogSize == 0?"":dialogSize+1);
		var divId = "PageDialog"+(dialogSize == 0?"":dialogSize+1);
		var iframeId = "openListFrameId"+(dialogSize == 0?"":dialogSize+1);
		var settings = $.extend( {}, defaults, options );
		var title = settings['title'];
		var onCloseCallBack = settings['onClose'];
		var dg_width = settings['width'];
		var dg_height = settings['height'];
		var callBackjs = settings['callBack'];
		var urlparams = settings['urlparams'];
		var onLoadCallBack = settings['onLoadCallBack'];
		var enter = settings['enter'];
		var url = settings['url'];
		//可以是多个，以数组的形式存在，属性有{text:"按钮名称",index:按钮位置(从0开始),handler:function()}
		var newButtons = settings['newButtons'];
		if(null !=$(dialogId) && $(dialogId).length>0){
			return;
		}
		var buttons=new Array();
		if(settings['hasConfirm']==true){
			buttons.push({
				id:settings['confirmId'],
				text:'确定',
				handler:function(){
					//zhanghuajie 修改2015-12-21     避免页面js调用2次
					var jsonData=document.getElementById(iframeId).contentWindow.getDictionarySelections();
					if(jsonData && jsonData.length>0){
						callBackjs(jsonData);
						if(settings['okClose']){
							$(dialogId).dialog('close');
						}
					}
				}
			});
		}
		buttons.push({
			id:'closePageDialog',
			text:'关闭',
			handler:function(){
				$(dialogId).dialog('close');}
		});
		var newButtonsLength = newButtons.length;
		var funObject = {};
		for(var i = 0; i < newButtonsLength; i++){
        	var oldHandler = newButtons[i].handler;
        	if(isNull(newButtons[i].id)){
        		newButtons[i].id = "dialog_id_"+i;
        	}
        	funObject[newButtons[i].id] = oldHandler;
        	if(typeof oldHandler == "function"){
        		newButtons[i].handler = function(){
        			var fun = funObject[$(this).attr("id")];
        			if(typeof fun == "function"){
        				fun.call(this,dialogId,iframeId);
        			}
        		}
        	}
        	var index = newButtons[i].index;
        	if(!isNull(index) && index < buttons.length){
        		buttons.splice(index,0,newButtons[i]);
        	}
	    }
		var dictionaryDiv = 
		'<div id="'+divId+'" class="easyui-dialog page-dialog" closed="true" modal="true" >'+
			'<iframe scrolling="no" id="'+iframeId+'" name="'+iframeId+'" frameborder="0"  style="width:100%;height:98%;"></iframe>'+
		'</div>'; 
		$(document.body).append(dictionaryDiv); 
		
		$(dialogId).dialog({
	 		collapsible:false,
	 		minimizable:false,
	 		maximizable:false,
	 		resizable:false,
	 		draggable:true,
	 		onOpen:settings['onOpen'],
	 		inline:true,
	 		shadow:false,
	 		title:title,
		    width:dg_width,
		    height:dg_height,
		    modal:true,
		    onClose:function(){
				$(dialogId).parent().remove();
				if(typeof onCloseCallBack == "function"){
					onCloseCallBack();
				}
		    },
		    buttons:buttons
		});
		var baseParams = "";
		for ( var p in urlparams) {
			baseParams = baseParams + p + "=" + urlparams[p] + "&";
		}
		if (baseParams.length > 0
				&& baseParams.charAt(baseParams.length - 1) == '&') {
			baseParams = baseParams.substring(0, baseParams.length - 1);
		}
		if(baseParams.length>0){
			url = url +"?"+baseParams;
		}
		$(dialogId).dialog('open');
		var listFrame = $("#"+iframeId);
		listFrame.attr("src", url); 
		listFrame.load(function() {
			if(null != onLoadCallBack){
				onLoadCallBack(openListFrameId);
			}
			if(enter){
				$("#"+iframeId).contents().find("body").bind('keyup',function(event){
					var keyValue = event.which;
					if(keyValue == KEY_VALUE.KEY_ENTER){
						var jsonData=openListFrameId.getDictionarySelections();
						if(jsonData && jsonData.length>0){
							callBackjs(jsonData);
							if(settings['okClose']){
								$(dialogId).dialog('close');
							}
						}
					}
				});
			}
		});
	},
	closeSelector: function(){
		$(dialogId).dialog('close');
	}
};
var KEY_VALUE = {
		KEY_UP:38,
		KEY_DOWN:40,
		KEY_ENTER:13,
		KEY_LEFT:37,
		KEY_RIGHT:39
};
(function($){
	$.fn.data_log = function(options){
		var defaultOptions = {
				sourceId:function(){return "";}
		}
		var setting=$.extend({},defaultOptions,options);
		$(this).click(function(){
			var url=BASE_PATH + '/cuDataLogController/toSearchList';
			var sourceIdFunction = setting["sourceId"];
			var sourceId = sourceIdFunction.call(this);
			if(!isNull(sourceId)){
				url = url + "?sourceId = " + sourceId;
			}
		 	openWindow('修改日志',url,900,600,true);
		});
		
	}
	$.fn.oasis_datagrid_exporter = function(options){
		// update by zhanghj 20160923  默认导出可以自定义名称
		var defaultOptions = {
				url:BASE_PATH+'/reportController/exportExcel',//导出地址，默认导出需要在export.xml中配置，并额外传递参数exportCode
				table:'',//表格ID
				rename:true,//导出是是否重命名
				defaultFileName:parent.getMenuName(),//默认名称
				tablePrimaryField:''//列表数据主键字段
		};
		var setting=$.extend({},defaultOptions,options);
		var url=setting["url"];
		var rename=setting["rename"];
		var defaultFileName=setting["defaultFileName"];
		var table=setting["table"];
		var tablePrimaryField=setting["tablePrimaryField"];
		
		var tmpForm = $("#temp_dowmload_form");
		if(tmpForm || tempForm.length == 0){
			$("body").append(
					"<form method='post' id='temp_dowmload_form'>" +
					"</form>"
			);
			tmpForm = $("#temp_dowmload_form");
		}
		$(this).click(function(){
			tmpForm.html("");
			var exportFunction = function(fileName){
				var options = $("#"+table).datagrid('options');
				var queryParams = options.queryParams;
				$.each(queryParams, function(key, value) {
					var input = $("<input>");
					input.attr("type", "hidden");
					input.attr("name", key);
					input.attr("value", value);
					tmpForm.append(input);
				});
				var selections = $("#"+table).datagrid('getSelections');
				if(selections.length > 0){
					var idsArray = new Array(selections.length);
					for(var i = 0; i < selections.length; i++){
						idsArray[i] = selections[i][tablePrimaryField];
					}
					var input = $("<input>");
					input.attr("type", "hidden");
					input.attr("name", "IN_PREPARY_FIELD");
					input.attr("value", idsArray.join("@"));
					queryParams['IN_PREPARY_FIELD']=idsArray.join("@");
					tmpForm.append(input);
				}
				var input = $("<input>");
				input.attr("type", "hidden");
				input.attr("name", "sort");
				input.attr("value", options.sortName);
				tmpForm.append(input);
				
				var input2 = $("<input>");
				input2.attr("type", "hidden");
				input2.attr("name", "order");
				input2.attr("value", options.sortOrder);
				tmpForm.append(input2);
				//普通列表导出
				if(setting.exportCode){
					var inputExportCode = $("<input>");
					input2.attr("type", "hidden");
					input2.attr("name", "exportCode");
					input2.attr("value", setting.exportCode);
					tmpForm.append(inputExportCode);
				}
				//自定义导出列头
				if(setting.execleHeaders && setting.execleHeaders!=''){
					var inputExecleHeader = $("<input>");
					inputExecleHeader.attr("type", "hidden");
					inputExecleHeader.attr("name", "execleHeaders");
					inputExecleHeader.attr("value", setting.execleHeaders);
					tmpForm.append(inputExecleHeader);
				}
				// update by zhanghj 20161025  超过1万，异步导出!!!
				if(setting.exportCode && setting.exportCode!=''){
					//$.plugin.plugLoading("正在导出，请稍后...");
					queryParams['exportCode']=setting.exportCode;
					queryParams['sort']=options.sortName;
					queryParams['order']=options.sortOrder;
					queryParams['fileName']=fileName;
					$.ajax({
						type:"POST",
						dataType:"JSON",
						data:queryParams,
						url:BASE_PATH+'/reportController/getTotalNormal',
						success:function(data){
							//$.plugin.close();
							//根据总数判断
							if(data==0){
								$.messager.alert('提示信息','当前条件没有可导数据!');
							}else if(data>10000){//大于10000异步导出
								$.messager.alert('提示信息','导出数据量大，已转到后台执行。请到“下载任务”查看下载进度。');
								$.ajax({
									type:"POST",
									dataType:"JSON",
									data:queryParams,
									url:BASE_PATH+'/reportController/saveExportInfo',
									success:function(result){
									}
								});
							}else{//小于10000实时导出
								tmpForm.attr("method", "post");
								tmpForm.attr("action", url);
								tmpForm.submit();
							}
						},
						error:function(data){
							//$.plugin.close();	
							alert("导出异常请联系管理员!");
						}
					});
				}else{
					tmpForm.attr("method", "post");
					tmpForm.attr("action", url);
					tmpForm.submit();
				}
			}
			if(rename){
				if($("#FILE_RENAME_DIALOG").length == 0){
					$("body").append(
							"<div id='FILE_RENAME_DIALOG' style='padding:20px 10px 10px 10px;'>" +
							"文件名：<input type='text' id='FILE_RENAME_INPUT' name='FILE_RENAME_INPUT' style='width:260px;' value='"+defaultFileName+"'/>"+
							"</div>"
					);
				}
				$("#FILE_RENAME_INPUT").val(defaultFileName);
				$('#FILE_RENAME_DIALOG').dialog({
		     		collapsible:false,
		     		minimizable:false,
		     		maximizable:false,
		     		resizable:false,
		     		draggable:false,
		     		inline:true,
		     		shadow:false,
		     		closed:true,
		     		top:120,
		     		title:"导出文件",
		    	    width:350,
		    	    height:150,
		    	    modal:true,
		    	    buttons:[
		    	        {
			    			text:'确认',
			    			handler:function(){
			    				var input = $("<input>");
			    				input.attr("type", "hidden");
			    				input.attr("name", "fileName");
			    				input.attr("value", $("#FILE_RENAME_INPUT").val());
			    				tmpForm.append(input);
			    				exportFunction.call(exportFunction,$("#FILE_RENAME_INPUT").val());
			    				$("#FILE_RENAME_DIALOG").dialog("close");
			    			}
		    	        },
		    	        {
			    			text:'关闭',
			    			handler:function(){
			    				$("#FILE_RENAME_DIALOG").dialog("close");
			    			}
		    	        }
		    	    ]
		    	});
		    	$('#FILE_RENAME_DIALOG').dialog("open");
				
			}else{
				exportFunction.call(exportFunction,defaultFileName);
			}
		});
	}
	
	$.fn.oasis_common_exporter = function(options){
		var defaultOptions = {
				url:'',//导出地址
				rename:false,//导出是是否重命名
				defaultFileName:'',//默认名称
				postParameters:function(){return {}}//列表数据主键字段
		};
		var setting=$.extend({},defaultOptions,options);
		var url=setting["url"];
		var rename=setting["rename"];
		var defaultFileName=setting["defaultFileName"];
		var postParameters=setting["postParameters"];
		
		var tmpForm = $("#temp_dowmload_form");
		if(tmpForm || tempForm.length == 0){
			$("body").append(
					"<form method='post' id='temp_dowmload_form'>" +
					"</form>"
			);
			tmpForm = $("#temp_dowmload_form");
		}
		$(this).click(function(){
			tmpForm.html("");
			var that = this;
			var exportFunction = function(){
				if(typeof postParameters == "function"){
					var parameters = postParameters.call(that);
					if(typeof parameters == "string"){
						parameters = eval("("+parameters+")");
					}
					for(key in parameters){
						var input = $("<input>");
						input.attr("type", "hidden");
						input.attr("name", key);
						input.attr("value", parameters[key]);
						tmpForm.append(input);
					}
				}
				console.log(typeof postParameters);
				tmpForm.attr("method", "post");
				tmpForm.attr("action", url);
				tmpForm.submit();
			}
			if(rename){
				if($("#FILE_RENAME_DIALOG").length == 0){
					$("body").append(
							"<div id='FILE_RENAME_DIALOG' style='padding:20px 10px 10px 10px;'>" +
							"文件名：<input type='text' id='FILE_RENAME_INPUT' name='FILE_RENAME_INPUT' style='width:260px;' value='"+defaultFileName+"'/>"+
							"</div>"
					);
				}else{
					$("#FILE_RENAME_INPUT").val(defaultFileName);
				}
				$('#FILE_RENAME_DIALOG').dialog({
		     		collapsible:false,
		     		minimizable:false,
		     		maximizable:false,
		     		resizable:false,
		     		draggable:false,
		     		inline:true,
		     		shadow:false,
		     		closed:true,
		     		top:120,
		     		title:"导出文件",
		    	    width:350,
		    	    height:150,
		    	    modal:true,
		    	    buttons:[
		    	        {
			    			text:'确认',
			    			handler:function(){
			    				var input = $("<input>");
			    				input.attr("type", "hidden");
			    				input.attr("name", "fileName");
			    				input.attr("value", $("#FILE_RENAME_INPUT").val());
			    				tmpForm.append(input);
			    				exportFunction.call(that);
			    				$("#FILE_RENAME_DIALOG").dialog("close");
			    			}
		    	        },
		    	        {
			    			text:'关闭',
			    			handler:function(){
			    				$("#FILE_RENAME_DIALOG").dialog("close");
			    			}
		    	        }
		    	    ]
		    	});
		    	$('#FILE_RENAME_DIALOG').dialog("open");
				
			}else{
				exportFunction.call(that);
			}
		});
	}
	/**********************公共多选框(人员与客户)-start**********************/
	$.fn.oasis_selector = function(options,selector_xml,propertyId,propertyName){
		var defaultOptions = {
				id:'',//文本框ID
				title:'请选择',//选择框标题
				buttons:[],//自定义按钮{title:按钮名,
							//clickEvent:按钮点击事件,
							//type:按钮类型（选择（SELECT）和清除（DELECT），替换组件默认按钮，只有设置replaceBtn为true是才生效）,
							//index:按钮位置,class:文本框类} 文本框后面位置
				usedType:"LIST",//组件使用类型：LIST（列表查询）、DETAIL（新增页或者修改页）
				muilt:true,//是否多选，默认不是多选
				enter:true,//是否只是回车，默认不支持回车
				blur:true,//失去焦点触发
				width:800,
				height:500,
				autoPrefix:true,//是否添加前缀，默认true
				parameterCallBack:'',//
				beforeSelectCallBack:'',
				clearCallBack:'',//回掉方法，可以不填(清空关联文本内容)
				callBack:'',//弹出框确认回掉方法，可以不填
				defaultValue:'',//文本框隐藏域默认值
				defaultName:''//文本框默认显示值
		};
		var that = this;
		var setting=$.extend({},defaultOptions,options);
		var selector_id=setting["id"];
		var title=setting["title"];
		var muilt=setting["muilt"];
		var enter=setting["enter"];
		var width=setting["width"];
		var height=setting["height"];
		var callBack=setting["callBack"];
		var clearCallBack = setting["clearCallBack"];
		var beforeSelectCallBack = setting["beforeSelectCallBack"];
		var defaultValue=setting["defaultValue"];
		var defaultName=setting["defaultName"];
		var buttons = setting["buttons"];
		var blur = setting["blur"];
		var parameterCallBack = setting["parameterCallBack"];
		var top = setting["top"];
		var autoPrefix = setting["autoPrefix"];
		var usedType = setting["usedType"];
		
		var defaultButtons = new Array();
		var selectBtnId = null;
		var delectBtnId = null;
		var valueInputId = selector_id;
		var nameInputId = selector_id+'_name';
		if(usedType == "DETAIL"){
			var btnLen = buttons.length;
			if(btnLen == 0){
				buttons = [{title:'选择',type:'SELECT',class:'btn btn-primary btn-sm'}];
				btnLen = buttons.length;
			}
			for(var i = 0; i < btnLen; i++){
				var buttonSetting=$.extend({},defaultButtonsOptions,buttons[i]);
				if(buttonSetting['type']=="SELECT"){
					selectBtnId = 'oasis_'+selector_id+'_select';
				}else if(buttonSetting['type']=="DELECT"){
					delectBtnId = 'oasis_'+selector_id+'_delect';
				}
	        	defaultButtons.push('<button class="'+buttonSetting['class']+'" id="'+selectBtnId+'" style="margin-right:1px;" type="button">'+buttonSetting['title']+'</button>');
			}
		}else if(usedType == "LIST"){
			if(autoPrefix){
				valueInputId = "search_"+selector_id;
			}
			selectBtnId = "oasis_"+selector_id+"_select";
			delectBtnId = "oasis_"+selector_id+"_clean";
			defaultButtons.push('<button class="btn btn-default btn-xs icon-only blue" id="'+selectBtnId+'" style="margin-right:1px;" type="button"><i class="fa fa-plus"></i></button>');
			defaultButtons.push('<button class="btn btn-default btn-xs icon-only danger" id="'+delectBtnId+'" style="margin-left:1px;" type="button"><i class="fa fa-times "></i></button>');
			var btnLen = buttons.length;
			var defaultButtonsOptions = {title:'',clickEvent:'',index:null};
			for(var i = 0; i < btnLen; i++){
				var buttonSetting=$.extend({},defaultButtonsOptions,buttons[i]);
	        	var index = buttonSetting["index"];
	        	var btn = '<button class="btn btn-default btn-sm  icon-only blue" onclick="'+buttonSetting['clickEvent']+'()" style="margin-right:1px;margin-left:1px;" type="button">'+buttonSetting['title']+'</button>';
	        	if(!isNull(index) && index < defaultButtons.length){
	        		defaultButtons.splice(index,0,btn);
	        	}else{
	        		defaultButtons.push(btn);
	        	}
	        }
		}
		
		
		var oasisStaffHtml = 
		'<div class="input-group input-group-xs"><input type="hidden" class="form-control input-xs" id="'+valueInputId+'" name="'+valueInputId+'" value="'+defaultValue+'">'+
	    	'<input type="text" class="form-control input-xs choose-input" id="'+nameInputId+'" value="'+defaultName+'"'+'" title="'+defaultName+'">'+
	    	'<span class="input-group-btn">'+defaultButtons.join(" ")+
	        '</span>'+
	    '</div>';
		var currentData = {id:[],name:[]};
		if(!isNull(defaultValue) && !isNull(defaultName)){
			currentData = {id:defaultValue.split(","),name:defaultName.split(",")};
		}
		$(this).replaceWith(oasisStaffHtml);
		var syncSelect = function(){
			$('#'+valueInputId).val(currentData.id.join(","));
			var nameArrayStr = currentData.name.join(",");
			$('#'+nameInputId).val(nameArrayStr);
			$('#'+nameInputId).attr("title",nameArrayStr);
		}
		//默认回调方法(tack)
		var defaultCallBack = function(datas){
			var idArray = [];
			var nameArray = [];
			if(!muilt){
				currentData.id=[];
				currentData.name=[];
			}
			idArray = currentData.id;
			nameArray = currentData.name;
			var datasLen = datas.length;
			for(var i = 0; i < datasLen; i++){
				if($.inArray(datas[i][propertyId],idArray) == -1){
					idArray.splice(0,0,datas[i][propertyId]);
					nameArray.splice(0,0,datas[i][propertyName]);
				}
			}
			syncSelect.call(syncSelect);
			//?调用2次
			if(!isNull(callBack)){
				callBack = eval('('+callBack+')');
			}
			if(typeof callBack == "function"){
				callBack.call(that,datas);
			}
		}
		//chongzhi 
		var formResetAction = function(){
			$('#'+valueInputId).val("");
			$('#'+nameInputId).val("");
			$('#'+nameInputId).attr("title","");
			currentData.id=[];
			currentData.name=[];
		}
		$.registerResetCallBack(formResetAction);
		//选择按钮
		if(selectBtnId != null){
			$('#'+selectBtnId).click(function(){
				var url = BASE_PATH+"/dictionaryController/toListPage";
				callBack = eval(callBack);//?
				var queryParameters = {};
				if(!isNull(parameterCallBack)){//调用2次？？
					parameterCallBack = eval('('+parameterCallBack+')');
				}
				if(typeof parameterCallBack == "function"){
					queryParameters = parameterCallBack.call(parameterCallBack);
				}
				if(!isNull(beforeSelectCallBack) && beforeSelectCallBack != ''){
					beforeSelectCallBack = eval('(' + beforeSelectCallBack + ')');
				}
				if(typeof beforeSelectCallBack == "function"){
					var doSel = beforeSelectCallBack.call(beforeSelectCallBack);
					if(!doSel){
						return;
					}
				}
				//把文本框的值带到弹出框
				var textVal = $('#'+nameInputId).val();
				if(!isNull(textVal) && textVal != currentData.name.join(",")){
					queryParameters['oasis_search_fuzzy']=textVal;
				}
				var options =  {
						id:selector_xml,
						title:title,
						url:url,
						afterConfirmClose:'N',
						multiple:muilt,
						top:top,
						width:width,
						height:height,
						showLabel:true,
						callBack:defaultCallBack,
						urlparams:queryParameters,
						primaryField:propertyId,
						nameField:propertyName,
						selected:currentData,
						otherButtons:[
							{
								id: 'confirmAndClose',
							    text: '确定并关闭',
							    index: 1 ,
							    handler: function (datas,dialog) {
							        if (!isNull(datas)) {
							        	defaultCallBack.call(defaultCallBack, datas);
							        }
							        $(dialog).dialog('close');
							        
							    }
							}
					]
				};
				OasisHelper.openSelector(options);
			});
		}
		
		//清除按钮
		if(null != delectBtnId){
			$('#'+delectBtnId).click(function(){
				$('#'+valueInputId).val("");
				$('#'+nameInputId).val("");
				$('#'+nameInputId).attr("title","");
				currentData.id=[];
				currentData.name=[];
				if(!isNull(clearCallBack)){
					clearCallBack = eval('('+clearCallBack+')');
				}
				if(typeof clearCallBack == "function"){
					clearCallBack.call(this);
				}
			});
		}
		var quickSearch = function(searchValue){
			//xuzhen 20160923 1、 修复快捷检索数据，弹出框列表数据不对应问题
			var queryParameters = {};
    		if(typeof parameterCallBack == "function"){
    			queryParameters = parameterCallBack.call(parameterCallBack);
    		}
			queryParameters['oasis_search_fuzzy']=searchValue;
			$.ajax({
                type: "post", 
                dataType: "json",
                url: BASE_PATH + '/dictionaryController/quickSearch?id='+selector_xml,
                data: queryParameters,
                success: function (data) {
                    if (data.rs == 1) {
                    	defaultCallBack.call(defaultCallBack, data.datas);
                    } else if (data.rs == 0) {
                        jQuery.messager.alert('提示:',"没有查询到数据!");
                        syncSelect.call(syncSelect);
                    } else if (data.rs == 2) {
                    	syncSelect.call(syncSelect);
//                		var finalParams = $.extend({},queryParameters,params);
                    	var url = BASE_PATH+"/dictionaryController/toListPage";
                    	var options =  {
            					id:selector_xml,
            					title:title,
            					url:url,
            					afterConfirmClose:'N',
            					multiple:muilt,
            					urlparams:queryParameters,
            					width:width,
            					height:height,
            					showLabel:true,
            					callBack:defaultCallBack,
            					primaryField:propertyId,
            					nameField:propertyName,
            					selected:currentData,
            					otherButtons:[
            						{
            							id: 'confirmAndClose',
            						    text: '确定并关闭',
            						    index: 1 ,
            						    handler: function (datas,dialog) {
            						        if (!isNull(datas)) {
            						        	defaultCallBack.call(defaultCallBack, datas);
            						        }
            						        $(dialog).dialog('close');
            						    }
            						}
            				]
            			};
                        OasisHelper.openSelector(options);
                    } else {
                    	syncSelect.call(syncSelect);
                        jQuery.messager.alert('提示:',"请通知管理员，查询错误！");
                    }
                },
                error: function () {
                	syncSelect.call(syncSelect);
                    jQuery.messager.alert('提示:',"请通知管理员，查询错误！");
                }
            });
		}
		//回车和删除键
		$('#'+nameInputId).keyup(function(event){
			var which = event.which;
			var searchValue = $(this).val();
			if(enter){
				if(which==13 && !isNull(searchValue) && searchValue != currentData.name.join(",")){
					if(!isNull(beforeSelectCallBack) && beforeSelectCallBack != ''){
						beforeSelectCallBack = eval('(' + beforeSelectCallBack + ')');
					}
					if(typeof beforeSelectCallBack == "function"){
						var doSel = beforeSelectCallBack.call(beforeSelectCallBack);
						if(!doSel){
							return;
						}
					}
					$(this).val("");
					quickSearch.call(quickSearch,searchValue);
				}
			}
			//
			if(which == 8 && isNull(searchValue)){
				$('#'+valueInputId).val("");
				$('#'+nameInputId).val("");
				$('#'+nameInputId).attr("title","");
				currentData.id=[];
				currentData.name=[];
			}
		});
		
		//失去焦点
		if(blur){
			$('#'+nameInputId).blur(function(event){
				var searchValue = $(this).val();
				if(!isNull(searchValue) && searchValue != currentData.name.join(",")){
					if(!isNull(beforeSelectCallBack) && beforeSelectCallBack != ''){
						beforeSelectCallBack = eval('(' + beforeSelectCallBack + ')');
					}
					if(typeof beforeSelectCallBack == "function"){
						var doSel = beforeSelectCallBack.call(beforeSelectCallBack);
						if(!doSel){
							return;
						}
					}
					$(this).val("");
					quickSearch.call(quickSearch,searchValue);
				}
			});
		}
		
	}
	
	
	/**********************公共多选框(人员与客户)-end**********************/
	
	$.fn.datagridRowSOH = function(options){
		var defaults = {
				'primaryField': null,
				'afterElement':null
		};
		var settings = $.extend( {}, defaults, options );
		var preparyField = settings["primaryField"];
		if(null == preparyField){
			return;
		}
		var afterElement = settings["afterElement"];
		if(null == afterElement){
			return;
		}
		var btns = "<button type='button' class='btn btn-purple shiny btn-sm datagrid-row-hidden'>" +
				"<i class='fa fa-eye-slash'></i>隐藏所选行" +
				"</button>" +
				"<button type='button' class='btn btn-magenta shiny btn-sm datagrid-row-show'>" +
				"<i class='fa fa-eye'></i>保留所选行" +
				"</button>";
		$("#"+afterElement).after(btns);
		var datagrid = this;
		init();
		var oldOnclick = $("#s_btn").attr("onclick");
		$("#s_btn").removeAttr("onclick");
		$("#s_btn").click(function(){
			eval(oldOnclick);
			init();
		});
		
		function init(){
			$(".datagrid-row-show").unbind("click");
			$(".datagrid-row-hidden").unbind("click");
			var inPrimaryArray = new Array();
			var outPrimaryArray = new Array();
			inPrimaryArray = [];
			outPrimaryArray = [];
			var doSOH = function(){
				var queryParams = $(datagrid).datagrid('options').queryParams;
				queryParams["IN_PREPARY_FIELD"] = inPrimaryArray.join("@");
				queryParams["OUT_PREPARY_FIELD"] = outPrimaryArray.join("@");
				$(datagrid).datagrid({
					queryParams: queryParams, 
				});
			}
			$(".datagrid-row-show").bind("click",function(){
				inPrimaryArray = [];
				//outPrimaryArray = [];
				var selections = $(datagrid).datagrid("getSelections");
				for(var i = 0; i < selections.length; i++){
					if(inPrimaryArray.indexOf(selections[i][preparyField]) == -1){
						inPrimaryArray[inPrimaryArray.length]=selections[i][preparyField];
					}
				}
				if(inPrimaryArray.length>0){
					doSOH();
				}
			});
			$(".datagrid-row-hidden").bind("click",function(){
				//inPrimaryArray = [];
				//outPrimaryArray = []; 
				var selections = $(datagrid).datagrid("getSelections");
				for(var i = 0; i < selections.length; i++){
					if(outPrimaryArray.indexOf(selections[i][preparyField]) == -1){
						outPrimaryArray[outPrimaryArray.length]=selections[i][preparyField];
					}
				}
				if(outPrimaryArray.length>0){
					doSOH();
				}
			});
		}
		
	}
	/**
	 * 检索datagrid中的数据，并把结果显示在datagrid里面
	 * options:{bindInput:需要绑定的文本框,exp:表达式(例："(!isNull(row.productName) && row.productName.indexOf('@value') >= 0) || (!isNull(row.isbn) && row.isbn.indexOf('@value') >= 0)")}
	 */
	$.fn.datagridSearch=function(options){
		var defaults={
			bindInput:null,
			exp:null
		};
		var settings = $.extend( {}, defaults, options);
		var allRows = null;
		var datagridObject = this;
		var bindInput = settings["bindInput"];
		var exp = settings["exp"];
		if(null != bindInput){
			$("#"+bindInput).bind("keyup",function(event){
				if(event.which==13 || event.which==8){
					if(null == exp){
						return;
					}
					var value = $(this).val();
					if(null == allRows){
						allRows = getRows(datagridObject);
					}
					if(isNull(value)){
						$(datagridObject).datagrid("loadData",allRows);
						return;
					}
					value = $.trim(value);
					var tmpExp = exp.replace(/@value/g,value);
					
					var newArray = new Array();
					for (var i = 0; i < allRows.length; i++) {
						var row = allRows[i];
						if (eval(tmpExp)) {
							newArray.push(row);
						}
					}
					$(datagridObject).datagrid("loadData",newArray);
				}
			});
		}
	}
	$.fn.datagridEditEvent=function(options){
		//loadSelectIndex 值:LAST(选中最后一行) FIRST（选中第一行）
		//lastEditorStatus 在最后一行触发按键事件后编辑框的状态  值： CLOSE（关闭）
		var defaults = {
				'loadSelectIndex': null,
				'lastMove':$.noop(),
				'editorBlur':$.noop(),
				'lastEditorStatus':null,
				'lastMoveKey':[],
				'selectRowKey':[KEY_VALUE.KEY_ENTER],
				'selectRow':false,
				'clickRow':false,
				'eventKey':[KEY_VALUE.KEY_UP,KEY_VALUE.KEY_DOWN,KEY_VALUE.KEY_ENTER,KEY_VALUE.KEY_LEFT,KEY_VALUE.KEY_RIGHT]
		};
		var settings = $.extend( {}, defaults, options );
		var opLastMove = settings["lastMove"];
		var opEditorBlur = settings["editorBlur"];
		var loadSelectIndex = settings["loadSelectIndex"];
		var lastEditorStatus = settings["lastEditorStatus"];
		var lastMoveKey = settings["lastMoveKey"];
		var eventKey = settings["eventKey"];
		var selectRowKey = settings["selectRowKey"];
		var selectRow = settings["selectRow"];
		var clickRow = settings["clickRow"];
		var datagridObject = this;
		var editorOptions = {index:null};
		var options = $(datagridObject).datagrid("options");
		var columns = options.columns[0];
		//存放可编辑列的field
		var editorField = new Array();
		var editorFieldIndex = 0;
		// 内部仍然是对象，保存
		var editorInfo = {};
		
		//获取编辑框信息
		for(var i = 0; i < columns.length; i++){
			var column = columns[i];
			if(column.editor!=null){
				editorField[editorFieldIndex++]=column.field;
				editorInfo[column.field]={
						//type:column.editor.type,
						//max:column.editor.options.max,
						//min:column.editor.options.min, 
						//precision:column.editor.options.precision
				};
			}
		}
		
		//查找下一个编辑框
		function findNextField(oldField){
			for(var i = 0; i < editorField.length; i++){
				if(oldField == editorField[i]){
					if((i+1)<editorField.length){
						return editorField[i+1];
					}
					return null;
				}
			}
		}
		//查找上一个编辑框
		function findPreviousField(oldField){
			for(var i = 0; i < editorField.length; i++){
				if(oldField == editorField[i]){
					if((i-1)>=0){
						return editorField[i-1];
					}
					return null;
				}
			}
		}
		//最后一行键盘事件处理
		function lastDoSomething(key,keyName,index){
			if(null != lastEditorStatus && lastEditorStatus=="CLOSE"){
				$(datagridObject).datagrid("cancelEdit",index);
				editorOptions.index=null;
			}
			opLastMove(keyName);
		}
		//上下左右键 获取文档框内容   触发失去焦点事件
		function getInput(textEditor){
			if(!textEditor){
				return null;
			}
			if(textEditor.type=="text"){
				return textEditor.target[0];
			}else if(textEditor.type=="numberbox"){
				//这部分逻辑是什么样的？
				return $(textEditor.target[0]).next().children("input[type='text']");
			}else if(textEditor.type=="datebox"){
				return $(textEditor.target[0]).next().children("input[type='text']");
			}else if(textEditor.type=="combobox"){
				return $(textEditor.target[0]).next().children("input[type='text']");
			}else if(textEditor.type=="textbox"){
				return $(textEditor.target[0]).next().children("input[type='text']");
			}
			return null;
		}
		function keyEnter(event){
			var keyValue = event.which;
			//这部分是做什么逻辑的？
			var easyuiCombo = $(".panel.combo-p");
			for(var i = 0; i < easyuiCombo.length; i++){
				if($(easyuiCombo[i]).css("display")!="none"){
					return;
				}
			}
			if (keyValue == KEY_VALUE.KEY_ENTER || keyValue == KEY_VALUE.KEY_UP || 
					keyValue == KEY_VALUE.KEY_DOWN || keyValue == KEY_VALUE.KEY_LEFT || 
					keyValue == KEY_VALUE.KEY_RIGHT) {
				var tempRows =getRows(datagridObject);//换种方式取值
				var dataSize =tempRows.length;
				var field = event.data.field;
				var rowIndex = event.data.index;
				var lastInd = $(datagridObject).datagrid("getRowIndex",tempRows[dataSize-1]);
				//由于上、下、左、右键无法触发blur事件，获取文本框使用代码触发
				var textEditor = $(datagridObject).datagrid("getEditor",{index:rowIndex,field:field});
				var textInput = getInput(textEditor);
				if(textInput){
					$(textInput).trigger("blur");
				}
				switch (keyValue) {
				case KEY_VALUE.KEY_ENTER:
					if(eventKey.indexOf(KEY_VALUE.KEY_ENTER)<0){
						return;
					}
					if(selectRowKey.indexOf(KEY_VALUE.KEY_ENTER)>=0 && selectRow){
						$(datagridObject).datagrid("selectRow",rowIndex);
					}
					if(lastInd == rowIndex){
						if(lastMoveKey.indexOf(KEY_VALUE.KEY_ENTER)>=0){
							lastDoSomething(KEY_VALUE.KEY_ENTER,"ENTER",lastInd);
						}
					}else if(lastInd > rowIndex){
						changeEditor(rowIndex + 1,field);
					}
					break;
				case KEY_VALUE.KEY_UP:
					if(eventKey.indexOf(KEY_VALUE.KEY_UP)<0){
						return;
					}
					if(selectRowKey.indexOf(KEY_VALUE.KEY_UP)>=0 && selectRow){
						$(datagridObject).datagrid("selectRow",rowIndex);
					}
					if (rowIndex > 0) {
						changeEditor(rowIndex - 1,field);
					} else {
						changeEditor(rowIndex ,field);
					}
					if(lastInd == rowIndex){
						if(lastMoveKey.indexOf(KEY_VALUE.KEY_UP)>=0){
							lastDoSomething(KEY_VALUE.KEY_UP,"UP",lastInd);
						}
					}
					break;
				case KEY_VALUE.KEY_DOWN:
					if(eventKey.indexOf(KEY_VALUE.KEY_DOWN)<0){
						return;
					}
					if(selectRowKey.indexOf(KEY_VALUE.KEY_DOWN)>=0 && selectRow){
						$(datagridObject).datagrid("selectRow",rowIndex);
					}
					if (rowIndex < dataSize - 1) {
						changeEditor(rowIndex + 1 ,field);
					} else {
						changeEditor(rowIndex,field);
					}
					if(lastInd == rowIndex){
						if(lastMoveKey.indexOf(KEY_VALUE.KEY_DOWN)>=0){
							lastDoSomething(KEY_VALUE.KEY_DOWN,"DOWN",lastInd);
						}
					}
					break;
				case KEY_VALUE.KEY_RIGHT:
					if(eventKey.indexOf(KEY_VALUE.KEY_RIGHT)<0){
						return;
					}
					if(selectRowKey.indexOf(KEY_VALUE.KEY_RIGHT)>=0 && selectRow){
						$(datagridObject).datagrid("selectRow",rowIndex);
					}
					var newFieldR = findNextField(field);
					if (newFieldR != null) {
						changeEditor(rowIndex ,newFieldR)
					} else {
						changeEditor(rowIndex ,field);
					}
					if(lastInd == rowIndex){
						if(lastMoveKey.indexOf(KEY_VALUE.KEY_RIGHT)>=0){
							lastDoSomething(KEY_VALUE.KEY_RIGHT,"RIGHT",lastInd);
						}
					}
					break;
				case KEY_VALUE.KEY_LEFT:
					if(eventKey.indexOf(KEY_VALUE.KEY_LEFT)<0){
						return;
					}
					if(selectRowKey.indexOf(KEY_VALUE.KEY_LEFT)>=0 && selectRow){
						$(datagridObject).datagrid("selectRow",rowIndex);
					}
					var newFieldL = findPreviousField(field);
					if (newFieldL != null) {
						changeEditor(rowIndex ,newFieldL);
					} else {
						changeEditor(rowIndex ,field);
					}
					if(lastInd == rowIndex){
						if(lastMoveKey.indexOf(KEY_VALUE.KEY_LEFT)>=0){
							lastDoSomething(KEY_VALUE.KEY_LEFT,"LEFT",lastInd);
						}
					}
					break;
				}
			}
		}
		function editorBlur(event){
			cancelEdit(event.data.index,event.data.field);	
		}
		
		//先给编辑框绑定keydown事件，触发keydown事件之后再绑定keyup事件
		function editorKeyDown(event){
			var field = event.data.field;
			var index = event.data.index;
			$(this).unbind('keyup');
			$(this).bind('keyup',{index:index,field:field},keyEnter);
		}
		function bindEventDetailEditor(index){
			var editors = $(datagridObject).datagrid("getEditors",index);
			for(var i = 0; i < editors.length; i++){
				var input = getInput(editors[i]);
				if(input){
					$(input).bind('blur',{index:index,field:editors[i].field},editorBlur);
					$(input).bind('keydown',{index:index,field:editors[i].field},editorKeyDown);
				}
			}
			
		}
		function cancelEdit(rowIndex,field){
			//替换取值方式
			var rows =getRows(datagridObject);
			var editor = $(datagridObject).datagrid("getEditor",{index:rowIndex,field:field});
//			var input = getInput(editor);
			var input = null;
			if(editor.type=="text"){
				input = editor.target[0];
			}else if(editor.type=="numberbox"){
				input = $(editor.target[0]).next().children("input[type='text']");
			}else if(editor.type=="datebox"){
				input = $(editor.target[0]).next().children("input[type='text']");
			}else if(editor.type=="combobox"){
				input = $(editor.target[0]).next().children("input[class='textbox-value']");
			}else if(editor.type=="textbox"){
				input = $(editor.target[0]).next().children("input[type='text']");
			}
			var edInfo = editorInfo[field];
			var inputValue = $(input).val();
			if(!isNull(edInfo) && !isNull(inputValue)){
				if(edInfo.type == "numberbox"){
					var min = edInfo.min;
					var max = edInfo.max;
					var precision = edInfo.precision;
					if(!isNull(min) && Number(inputValue)<Number(min)){
						rows[rowIndex][field] = min;
						inputValue = min;
					}else if(!isNull(max) && Number(inputValue)>Number(max)){
						rows[rowIndex][field] = max;
						inputValue = max;
					}else if(!isNull(precision) && Number(precision)>0){
						rows[rowIndex][field] = Number(inputValue).toFixed(precision);
						inputValue = Number(inputValue).toFixed(precision);
					}else{
						var textInput = $(editor.target[0]).next().children("input[type='text']");
						if($(textInput).val() != inputValue){
							rows[rowIndex][field] = $(textInput).val();
						}else{
							rows[rowIndex][field] = inputValue;
						}
					}
				}else{
					rows[rowIndex][field] = inputValue;
				}
			}else{
				rows[rowIndex][field] = inputValue;
			}
			if(typeof opEditorBlur=="function"){
				opEditorBlur(rowIndex,field,inputValue);
			}
		}
		
		function changeEditor(index,field){
//			$(datagridObject).datagrid('selectRow',index);
			var currendIndex = editorOptions.index;
			if(null != currendIndex){
				$(datagridObject).datagrid("cancelEdit",currendIndex);
			}
			$(datagridObject).datagrid("beginEdit",index);
//			$(datagridObject).datagrid("selectRow",index);
			
			//给datebox combobox的onSelect方法中切入代码 选择之后聚焦当前编辑框
			var editors =  $(datagridObject).datagrid("getEditors",index);
			for(var i = 0; i < editors.length; i++){
				var selector = editors[i];
				if(selector.type=="datebox" || selector.type=="combobox"){
					var editOptions = null;
					if(selector.type=="datebox"){
						editOptions = $(selector.target).datebox("options");
					}else if(selector.type=="combobox"){
						editOptions = $(selector.target).combobox("options");
					}
					var oldSelect = editOptions.onSelect;
					editOptions.onSelect = function(d){
						var tx = $(this).next().children("input[type='text']");
	     				tx.focus();
						tx.select();
						oldSelect(d);
					}
				}
			}
			var isEditField = false;
			for(var i = 0; i < editorField.length; i++){
				if(field==editorField[i]){
					isEditField = true;
					break;
				}
			}
			if(isEditField){
				var editor = $(datagridObject).datagrid("getEditor",{index:index,field:field});
				var input = getInput(editor);
				if(input){
					input.focus();
					input.select();
				}
			}
			bindEventDetailEditor(index);
			editorOptions.index = index;
		}
		//在datagrid的onClickCell和onLoadSuccess方法中切入事件代码
		var oldOnClickCellFunction = options.onClickCell;
		var oldOnLoadSuccessFunction = options.onLoadSuccess;
		options.onClickCell = function(index,field,value){
			var isEditField = false;
			if(null != editorOptions.index){
				//替换取值方式
				var rows =getRows(datagridObject);
				var editors = $(datagridObject).datagrid("getEditors",editorOptions.index);
				for(var i = 0; i < editors.length; i++){
					if(editors[i].type=="combobox"){
						var input = $(editors[i].target[0]).next().children("input[type='hidden']");
						rows[editorOptions.index][editors[i].field]=$(input).val();
					}
				}
			}
			
			for(var i = 0; i < editorField.length; i++){
				if(field==editorField[i]){
					isEditField = true;
					break;
				}
			}
			if(isEditField){
				changeEditor(index,field);
			}
			oldOnClickCellFunction(index,field,value);
		}
		if(clickRow){
			var oldOnClickRowFunction = options.onClickRow;
			options.onClickRow = function(index, row){
				var isEditField = false;
				if(null != editorOptions.index){
					//替换取值方式
					var rows =getRows(datagridObject);
					var editors = $(datagridObject).datagrid("getEditors",editorOptions.index);
					for(var i = 0; i < editors.length; i++){
						if(editors[i].type=="combobox"){
							var input = $(editors[i].target[0]).next().children("input[type='hidden']");
							rows[editorOptions.index][editors[i].field]=$(input).val();
						}
					}
				}
				changeEditor(index,editorField[0]);
				oldOnClickRowFunction(index, row);
			}
		}
		options.onLoadSuccess = function(data){
			//替换取值方式 zhanghuajie 20160127
			var newRows =getRows(datagridObject);
			if(newRows.length>0 && editorField.length>0){
				editorOptions.index = null;
				if(loadSelectIndex != null){
					if(loadSelectIndex=="LAST"){
						changeEditor(newRows.length-1,editorField[0]);
//						$(datagridObject).datagrid("selectRow",newRows.length-1);
					}else if(loadSelectIndex=="FIRST"){
						changeEditor(0,editorField[0]);
//						$(datagridObject).datagrid("selectRow",0);
					}
				}
			}
			oldOnLoadSuccessFunction(data);
		}
		editorOptions["changeEditor"]=changeEditor;
		return editorOptions;
	}
	/**
	 * 详情页datagrid高度自适应
	 * @author XuZhen
	 *
	 */
	$.fn.datagridAutoFit=function(options){
		var defaults = {
				'otherElements': [],
				'constant':0
				};
		var settings = $.extend( {}, defaults, options );
		var otherElements = settings['otherElements'];
		var datagridObj = this;
		function otherElementHeight(){
			var height = 0;
			for(var i = 0; i < otherElements.length; i++){
				var otherElementArray = $(otherElements[i]);
				for(var j = 0; j < otherElementArray.length; j++){
					if($(otherElementArray[j]).is(":visible")){
//						console.log(otherElementArray[j]);
//						console.log(Number($(otherElementArray[j]).height()));
//						console.log("margin-top:"+$(otherElementArray[j]).css("margin-top"));
//						console.log("margin-bottom:"+$(otherElementArray[j]).css("margin-bottom"));
						height+=Number($(otherElementArray[j]).height());
					}
				}
			}
			return height;
		}
		function changeDataGridHeight(){
			var mainHeight = $(window.parent.document).height();
//			console.log("mainHeight:"+mainHeight);
			var finalHeight = mainHeight - (otherElementHeight()+Number(settings['constant']));
			if(finalHeight < 100){
				finalHeight = 280;
			}
			$(datagridObj).datagrid('resize', {
				height:finalHeight
			});
		}
		changeDataGridHeight();
		$(window).resize(function(){
			changeDataGridHeight();
		});
	}
	//对指定input或textarea值中的特殊字符进行处理
	$.fn.htmlVal = function(){
		var val = $(this).val();
		if(isNull(val)){
			val = "";
		}
		val = restoreHtml(val);
//		val = val.replace(new RegExp(/\>/g), "&gt;");  
//		val = val.replace(new RegExp(/\</g), "&lt;");
//		val = val.replace(new RegExp(/\n/g), "<br/>");
//		val = val.replace(new RegExp(/\s/g), "&nbsp;");  
//		val = val.replace(new RegExp(/\"/g), "&quot;");  
//		val = val.replace(new RegExp(/\'/g), "&#39;");  
//		val = val.replace(new RegExp(/\\/g), "\\\\");  
//		val = val.replace(new RegExp(/\r/g), "\\r"); 
		return val;
	}
})(jQuery);

//查看日志
function lookOrderLog(orderCode){
	$("body").append("<div id='orderLogDialog' style=\"overflow:auto\"><div id='orderLogHtml'></div></div>");
	$('#orderLogDialog').dialog({
		collapsible:false,
		minimizable:false,
		maximizable:false,
		resizable:false,
		draggable:false,
		inline:true,
		shadow:false,
		closed:true,
		title:"日志详情",
	    width:500,
	    height:300,
	    modal:true,
	    onClose:function(){
	    	$("#orderLogHtml").html("");
	    },
	    buttons:[{
			text:'关闭',
			handler:function(){
				$("#orderLogDialog").dialog("close");
			}
		}]
	});
	
	$.post(
	BASE_PATH+"/cuOperatorLogController/lookOrderLog/"+orderCode,
	function(data){
		var orderLogList = data.orderLog;
		var orderLog = "";
		if(orderLogList.length == 0){
			$.messager.alert("系统提示","暂无日志信息","info");
			return ;
		}
		if(orderLogList.length >0 ){
			for(var i = 0; i<orderLogList.length; i++){
				var contents = cutString(orderLogList[i].contents, 50);
				orderLog += "<p style =\"height:15px\">"
							 + "<span style = \"color:blue\">"+orderLogList[i].operatorDate +"</span>" + "&nbsp;&nbsp;"
							 + "<span style = \"color:red\">"+orderLogList[i].operatorStaffName +"</span>" + "&nbsp;&nbsp;"
							 + "<a href=\"javascript:void(0)\" title=\""+ orderLogList[i].contents + "\">" + contents + "</a>";
				
				orderLog +=	"</p><div id=\"content\" style=\"BORDER-TOP:#00686b 1px dashed; OVERFLOW: hidden; HEIGHT: 1px\"></div>";		
			}
			$("#orderLogHtml").html(orderLog);
		}
		$('#orderLogDialog').dialog('open');
	}
);
}

	/**参数说明：
	 * 根据长度截取先使用字符串，超长部分追加…
	 * str 对象字符串
	 * len 目标字节长度
	 * 返回值： 处理结果字符串
	 */
	function cutString(str, len) {
	    //length属性读出来的汉字长度为1
	    if(str.length*2 <= len) {
	        return str;
	    }
	    var strlen = 0;
	    var s = "";
	    for(var i = 0;i < str.length; i++) {
	        s = s + str.charAt(i);
	        if (str.charCodeAt(i) > 128) {
	            strlen = strlen + 2;
	            if(strlen >= len){
	                return s.substring(0,s.length-1) + "...";
	            }
	        } else {
	            strlen = strlen + 1;
	            if(strlen >= len){
	                return s.substring(0,s.length-2) + "...";
	            }
	        }
	    }
	    return s;
	}
/**
 * 有多选的控件时，选择全部以外的条件，自动取消选中全部 方法冗余了
 * @param controlId
 */
function unselectAllForSelect(controlId){
	$('#'+controlId).combobox({
		onSelect:function(node){
			var selectValue = $(this).combobox('getValues');
			console.log(selectValue);
			if(selectValue && selectValue.length > 1){
				for(var i = 0; i < selectValue.length; i++){
					if(selectValue[i] == ''){
						$(this).combobox('unselect', '');
					}else if(selectValue[i] == 'cbb_all'){
						$(this).combobox('unselect', 'cbb_all');
					}
				}
			}
		}
	});
}
function oasisEncode(srcCode){
	return window.btoa(encodeURIComponent(srcCode));
}
function oasisDecode(srcCode){
	return decodeURIComponent(window.atob(srcCode));
}

//cookie操作
/**
 * 设置cookie
 * @param name 键
 * @param value 值
 * @returns
 */
function setCookie(name,value){
	var Days = 30;
	var exp = new Date();
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

/**
 * 获取cookie
 * @param name
 * @returns
 */
function getCookie(name){
	var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	if(arr=document.cookie.match(reg)){
		return unescape(arr[2]);
	}else{
		return null;
	}
}
/**
 * 删除cookie
 * @param name
 * @returns
 */
function delCookie(name){
	var exp = new Date();
	exp.setTime(exp.getTime() - 1);
	var cval=getCookie(name);
	if(cval!=null){
		document.cookie= name + "="+cval+";expires="+exp.toGMTString();
	}
}

/**
 * easyui-datebox控件扩展“清除”按钮
 */
$.fn.datebox.defaults.cleanText = '清空';

(function ($) {
    var buttons = $.extend([], $.fn.datebox.defaults.buttons);
    buttons.splice(1, 0, {
        text: function (target) {
            return $(target).datebox("options").cleanText
        },
        handler: function (target) {
            $(target).datebox("setValue", "");
            $(target).datebox("hidePanel");
        }
    });
    $.extend($.fn.datebox.defaults, {
        buttons: buttons
    });

})(jQuery)